import { defineStore } from 'pinia'
import axios from 'axios'
import { ListRes, ListType } from '../../types/data'

const userNavStore = defineStore('nav', {
  state() {
    return {
      count: 90,
      // 类型断言(我比ts更了解这个数据应该是什么类型)
      list: [] as ListType,

      // 记录当前高亮
      activeID: -1,
    }
  },

  actions: {
    async getList() {
      const res = await axios.get<ListRes>(
        'http://geek.itheima.net/v1_0/channels'
      )
      // console.log(res.data.data.channels)
      this.list = res.data.data.channels
      this.activeID = res.data.data.channels[0].id
    },

    // 修改点击的id
    changeActiveID(id: number) {
      this.activeID = id
    },

    //
  },

  getters: {},
})

export default userNavStore
